
package br.ita.model.dao;

import br.ita.model.entities.Login;
import br.ita.model.entities.Points;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.Query;

public class PointsDAO implements DAO {
    
    JPAUtil jpautil = new JPAUtil();    
    private EntityManager em = jpautil.getEntityManager();

    @Override
    public void insert(Object o) {
        em.getTransaction().begin();
        em.persist(o);
        em.getTransaction().commit();
    }

    @Override
    public void update(Object o) {
        em.getTransaction().begin();
        em.merge(o);
        em.getTransaction().commit();
    }

    @Override
    public void delete(Object o) {
        em.getTransaction().begin();
        em.remove(retrieve(o));
        em.getTransaction().commit();
    }

    @Override
    public List findAll() {
        List<Points> points = new ArrayList<Points>();
        Query query =  em.createQuery("SELECT * FROM pontos");
        points = query.getResultList();
        return points; 
    }

    @Override
    public Entity retrieve(Object o) {
        Points resultado = new Points();
        resultado = em.find(Points.class, o);
        return (Entity) resultado;
    }
}
